# -*- coding=utf-8-*-
"""
@File:memory_selection
@Author:Created by Han X.Y
@Date:on 2021/7/8 9:36 
"""
import re


def str_find(raw_string, sub_str):
    """
    在指定字符中查找子串，如果存在则返回开始位置，否则返回-1
    """
    try:
        if len(sub_str) == 0:
            return 0
        return re.search(sub_str, raw_string).span()[0]
    except:
        return -1


def str_find2(raw_string, sub_str):
    if len(sub_str)==0:
        return 0
    i=0#原始字符串
    j=0#子串
    while i <len(raw_string) and j <len(sub_str):
        print(i, j)
        if raw_string[i]==sub_str[j]:
            i+=1
            j+=1
        else:
            i+=1
            j=0
    if j==0:
        return -1
    else:
        return i-j

if __name__=='__main__':
    print(str_find2('aaaaa','bba'))



